#include<iostream>
#include<vector>
using namespace std;
typedef pair<int, int> PII;
const int N = 2e5 + 10;
vector<PII>e[N];
int f[N];
int n;

void dfs(int u, int k, int fa)
{
	for (PII v : e[u]) {
		if (v.first == fa)continue;
		f[v.first] = v.second > k ? f[u] : f[u] + 1;
		dfs(v.first, v.second, u);
	}
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n;
		for (int i = 1; i <= n; i++) {
			e[i].clear();
			f[i] = 0;
		}
		for (int i = 1; i <= n - 1; i++) {
			int u, v;
			scanf_s("%d%d", &u, &v);
			e[u].push_back({ v,i });
			e[v].push_back({ u,i });
		}
		f[1] = 1;
		dfs(1, 0, 0);
		int ans = 0;
		for (int i = 1; i <= n; i++)ans = max(ans, f[i]);
		cout << ans << endl;
	}
	return 0;
}